package com.sq.universe.system.utils;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AutoCodeUtil {

    public static void  main(String[] args){
        test();
    }


    public static void test(){
        Configuration cfg = new Configuration(Configuration.VERSION_2_3_30);
        try {
//            cfg.setDirectoryForTemplateLoading(new File("D:\\10segaFie"));
//            Map root = new HashMap();
//            List<String> fieldnames = new ArrayList<>();
//            Map fieldtypes = new HashMap();
//            root.put("domainname", "User");
//            root.put("idtype","Long");
//            fieldnames.add("username");
//            fieldtypes.put("username","String");
//            fieldnames.add("password");
//            fieldtypes.put("password","String");
//            fieldnames.add("email");
//            fieldtypes.put("email","String");
//            fieldnames.add("age");
//            fieldtypes.put("age","Short");
//            root.put("fieldnames", fieldnames);
//            root.put("fieldtypes", fieldtypes);
//            String path =  "D:\\10segaFie\\UserDao.java";
//            new File(path).delete();
//            Template t = cfg.getTemplate("dao.ftl");
//            Writer out = new OutputStreamWriter(new FileOutputStream(path), "UTF-8");
//            try {
//                t.process(root, out);
//            } catch (TemplateException e) {
//                e.printStackTrace();
//            }
//            System.out.println("Finish the work");
            //得到classpath的路径
//            String classpath = this.getClass().getResource("/").getPath();
//            //定义模板路径(template存放着ftl文件)
//            cfg.setDirectoryForTemplateLoading(new File(classpath+"/template/"));
//            //获取模板文件内容
//            Template template = cfg.getTemplate("index.ftl");
//            String path =  "D:\\10segaFie\\UserDao111.java";
//            Writer out = new OutputStreamWriter(new FileOutputStream(path), "UTF-8");
//            try {
//                template.process(new HashMap<>(), out);
//            } catch (TemplateException e) {
//                e.printStackTrace();
//            }
//            System.out.println("Finish the work");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
